package pub.guoxin.oops.manager.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import pub.guoxin.oops.constants.TopicName;
import pub.guoxin.oops.manager.service.CheckoutAlarmService;
import pub.guoxin.oops.model.CommunicationData;
import pub.guoxin.oops.msg.MessageDataListener;
import pub.guoxin.oops.utils.JsonUtils;

import javax.annotation.Resource;

@Slf4j
@Component
public class DataAlarmMessageDataListener implements MessageDataListener {

    @Resource
    private CheckoutAlarmService checkoutAlarmService;

    @KafkaListener(topics = {TopicName.DATA_ALARM_TOPIC})
    public void processMessage(ConsumerRecord<String, String> consumerRecord) {
        String data = consumerRecord.value();
        CommunicationData communicationData = JsonUtils.json2obj(data, CommunicationData.class);
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ starting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.println(communicationData.toString());
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ending ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    }

}
